import 'package:flutter/material.dart';
import 'package:kugou/src/bloc/sing_rank_bloc.dart';
import 'package:kugou/src/models/sing_rank.dart';

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //newSingRankBloc.getNewSingRank();
    singRankBloc.getSingRank();
    return Scaffold(
      appBar: AppBar(
        title: Text(this.title),
      ),
      body: SingleChildScrollView(
        child: StreamBuilder(
            //stream: newSingRankBloc.newSingRank,
            stream: singRankBloc.singRank,
            builder: (context, AsyncSnapshot<SingRank> snapshot) {
              // ignore: missing_return
              if (snapshot.hasData) {
                return _buildContent(snapshot.data, context);
              } else if (snapshot.hasError) {
                return Text(snapshot.error.toString());
              }
              return Container();
            }),
      ),
    );
  }

  Widget _buildContent(SingRank data, context) {
    var widgets = <Widget>[];
    for (var i in data.rank.list) {
     // widgets.add(Image.network());
      widgets.add(Text(i.rankname));
      widgets.add(Image.network(i.imgurl));
    }
    return Column(children: widgets);
  }
}
